﻿using WikiMaml.Renderers;
using Xunit;
using Xunit.Extensions;

namespace WikiMaml.Facts.Renderers
{
    public class TopicLinkRendererFacts
    {
        public class CanExpand
        {
            [Theory]
            [InlineData(MamlScopeName.TopicLink)]
            [InlineData(MamlScopeName.TopicLinkNoText)]
            public void Should_be_able_to_expand_scope_name(string scopeName)
            {
                var renderer = new TopicLinkRenderer();

                bool result = renderer.CanExpand(scopeName);

                Assert.True(result);
            }
        }

        public class Expand
        {
            [Fact]
            public void Should_expand_topic_link_with_no_text()
            {
                var renderer = new TopicLinkRenderer();

                string result = renderer.Expand(MamlScopeName.TopicLinkNoText, "asdf-asdf", x => x, x => x);

                Assert.Equal("<link xlink:href=\"asdf-asdf\" />", result);
            }

            [Fact]
            public void Should_encode_href_with_no_text()
            {
                var renderer = new TopicLinkRenderer();

                string result = renderer.Expand(MamlScopeName.TopicLinkNoText, "asdf-asdf", x => x, x => "foo");

                Assert.Equal("<link xlink:href=\"foo\" />", result);
            }

            [Fact]
            public void Should_expand_topic_link_with_text()
            {
                var renderer = new TopicLinkRenderer();

                string result = renderer.Expand(MamlScopeName.TopicLink, "Test|asdf-asdf", x => x, x => x);

                Assert.Equal("<link xlink:href=\"asdf-asdf\">Test</link>", result);
            }

            [Fact]
            public void Should_expand_topic_link_with_text_and_encode_href()
            {
                var renderer = new TopicLinkRenderer();

                string result = renderer.Expand(MamlScopeName.TopicLink, "Test|asdf-asdf", x => x, x => "foo");

                Assert.Equal("<link xlink:href=\"foo\">Test</link>", result);
            }

            [Fact]
            public void Should_expand_topic_link_with_text_and_encode_text()
            {
                var renderer = new TopicLinkRenderer();

                string result = renderer.Expand(MamlScopeName.TopicLink, "Test|asdf-asdf", x => "foo", x => x);

                Assert.Equal("<link xlink:href=\"asdf-asdf\">foo</link>", result);
            }
        }
    }
}
